package com.example.pclimb.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.pclimb.model.TravelGuide;

import java.util.List;

/**
 * 旅游攻略数据访问接口
 */
@Dao
public interface TravelGuideDao {
    @Insert
    long insert(TravelGuide travelGuide);

    @Update
    void update(TravelGuide travelGuide);

    @Delete
    void delete(TravelGuide travelGuide);

    @Query("SELECT * FROM travel_guides WHERE id = :id")
    LiveData<TravelGuide> getTravelGuideById(int id);

    @Query("SELECT * FROM travel_guides WHERE authorId = :authorId")
    LiveData<List<TravelGuide>> getTravelGuidesByAuthorId(int authorId);

    @Query("SELECT * FROM travel_guides ORDER BY publishDate DESC")
    LiveData<List<TravelGuide>> getAllTravelGuides();

    @Query("SELECT * FROM travel_guides WHERE location LIKE '%' || :location || '%'")
    LiveData<List<TravelGuide>> getTravelGuidesByLocation(String location);

    @Query("SELECT * FROM travel_guides WHERE title LIKE '%' || :keyword || '%' OR content LIKE '%' || :keyword || '%'")
    LiveData<List<TravelGuide>> searchTravelGuides(String keyword);

    @Query("UPDATE travel_guides SET viewCount = viewCount + 1 WHERE id = :guideId")
    void incrementViewCount(int guideId);

    @Query("UPDATE travel_guides SET likeCount = likeCount + 1 WHERE id = :guideId")
    void incrementLikeCount(int guideId);

    @Query("SELECT * FROM travel_guides ORDER BY viewCount DESC LIMIT 10")
    LiveData<List<TravelGuide>> getTopViewedTravelGuides();

    @Query("SELECT * FROM travel_guides ORDER BY likeCount DESC LIMIT 10")
    LiveData<List<TravelGuide>> getTopLikedTravelGuides();
} 